import { BASEURL } from './config'
import http from './http'

// 导出 Socket
// export * from './socket'

export { BASEURL, WEB_BASEURL, imgBaseUrl } from './config'

// 七牛云传图
export const qiniuToken = (data, callback, fileType = 'image') =>
	http.get(`${BASEURL}/api/v1/qiniu-upload-token`, '', {
		finishFun: res => {
			uni.showLoading({
				title: '上传中',
				mask: true
			})
			uni.uploadFile({
				url: 'https://upload-z2.qiniup.com', // 七牛接口地址
				filePath: data,
				name: 'file',
				fileType,
				formData: {
					token: res.data.uptoken
				},
				...callback,
				success: e => {
					uni.hideLoading()
					callback?.success?.(e)
				}
			})
		}
	})

// 版本控制
export const getServerNo = params => http.get(`${BASEURL}/api/v1/version`, params)

// 获取版本号
export const getVersionInfo = data => http.get(`${BASEURL}/api/v1/version/show`, data)

// 生成小程序二维码
export const postMiniCode = data => http.post(`${BASEURL}/api/v1/mini-code`, data)

// 查询小程序二维码参数
export const getMiniCode = data => http.get(`${BASEURL}/api/v1/mini-code/${data}`)

// 获取省市区列表
export const getRegion = data => http.get(`${BASEURL}/api/v1/region`, data)

// 获取jssdk配置
export const getJsSdkConfig = data => http.get(`${BASEURL}/api/v1/wechat/js-sdk-config`, data)

// 发送验证码
export const postSms = data => http.post(`${BASEURL}/api/v1/send-sms-code`, data)

// 用户登录
export const postLogin = (data, type) => http.post(`${BASEURL}/api/v1/auth/login/${type}`, data)

// 用户注册
export const postRegister = data => http.post(`${BASEURL}/api/v1/user/register/sms`, data)

// 设置修改重设密码
export const putPassword = data => http.put(`${BASEURL}/api/v1/user/password`, data)

// 获取iv等加密信息传给后端解密(获取微信手机号码)
export const postGetMobile = data => http.post(`${BASEURL}/api/v1/wechat/decrypt-mobile`, data)

// 获取用户信息
export const getUsers = () => http.get(`${BASEURL}/api/v1/user`)

// 创建地址
export const createAddress = data => http.post(`${BASEURL}/api/v1/user/address`, data)

// 更新地址
export const updateAddress = data => http.put(`${BASEURL}/api/v1/user/address`, data)

// 我的地址
export const getMyAddressList = () => http.get(`${BASEURL}/api/v1/user/address`)

// 删除地址
export const delAddress = data => http.deleted(`${BASEURL}/api/v1/user/address`, data)

// 获取地址省市区编码
export const getAddressCode = data => http.post(`${BASEURL}/api/v1/region/decode`, data)

// 商品订单-下单数据
export const postCreateOrder = data => http.post(`${BASEURL}/api/v1/order/generate`, data)

// 商品订单-提交下单
export const postOrder = data => http.post(`${BASEURL}/api/v1/order`, data)

// 查询订单是否支付
export const getOrderStatus = id => http.get(`${BASEURL}/api/v1/pay/${id}`)

// 支付订单
export const postPayOrder = (pay_type, data) => http.post(`${BASEURL}/api/v1/pay/${pay_type}`, data)

// 绑定第三方账号
export const putBindThirdAccount = data =>
	http.post(`${BASEURL}/api/v1/user/bind-third-party/weixin`, data)

// 获取广告图
export const getBanners = code => http.get(`${BASEURL}/api/v1/banner/list?code=${code}`)

// 获取商品列表
export const getGoodsList = data => http.get(`${BASEURL}/api/v1/goods/search`, data)

// 获取通用富文本
export const getContentKey = key =>
	http.get(`${BASEURL}/api/v1/content-management/show-by-key?content_key=${key}`)
